clear all;
Fd = 44.2e6/4; 
Td = 1/Fd;
tmax = 0.001;
t = 0:Td:tmax;
N_PRN = 511; 
T_PRN = 0.001;
PRN = sign(randn(1, N_PRN));
ind_h = fix(mod(t/T_PRN, 1)*N_PRN) + 1;
h = PRN(ind_h);

A = 2;
f0 = 3e6;
phi = pi/4;
%u1(t1) = A * h .* cos(2*pi*f0*t1 + phi);
tau = (-0.001/2):(0.001/511):(0.001/2);
phiop = 0.6*phi;
%uop(t1) = A * h .* cos(2*pi*f0*t1 + phiop);
tt = (tmax/Td);
for ic = 1:length(tau)
    ind_h1 = fix(mod((t+tau(ic))/T_PRN, 1)*N_PRN) + 1;
    h1 = PRN(ind_h1);
    u1 = A * h1.* cos(2*pi*f0*(t+tau(ic)) + phi);
    uop = A * h.* cos(2*pi*f0*t + phiop);
    fcor(ic) = u1*uop';
end

plot(tau, fcor);
